package company.chubao;

import java.util.*;

public class Chu1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        String[] array1 = s1.split(" ");
        String[] array2 = s2.split(" ");
        StringBuffer sb = new StringBuffer();
        TreeMap<Integer, Integer> dict = new TreeMap<>();
        for (String s : array1) {
            int tmp = Integer.parseInt(s);
            dict.put(tmp, dict.getOrDefault(tmp, 0) + 1);
        }
        for (String s : array2) {
            int tmp = Integer.parseInt(s);
            if (dict.containsKey(tmp)) {
                Integer num = dict.get(tmp);
                for (int i = 0; i < num; i++) {
                    sb.append(tmp).append(" ");
                }
                dict.remove(tmp);
            }
        }
        for (Map.Entry<Integer, Integer> e : dict.entrySet()) {
            Integer num = e.getValue();
            for (int i = 0; i < num; i++) {
                sb.append(e.getKey()).append(" ");
            }
        }
        System.out.println(sb);
    }
}
